package com.qf.lanzhou.shop.admin.controller;

import com.qf.lanzhou.shop.admin.service.OrderService;
import com.qf.lanzhou.shop.pojo.entity.ParentsOrder;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Nerly
 * @Date 2021/1/13 14:45
 * @JDK 1.8
 * @Version 1.0
 */
@RestController
@Api(tags = "订单接口")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/getOrderPay")
    @ApiOperation("获取已支付订单")
    public BaseRespVO selectByPay() {
        List<ParentsOrder> parentsOrders = orderService.selectByPay();
        BaseRespVO baseRespVO = convertSuccessResult(parentsOrders);
        return baseRespVO;
    }

    @PostMapping("/sendGoods")
    @ApiOperation("/修改订单状态为发货")
    public BaseRespVO updateStatusToSend(ParentsOrder parentsOrder) {
        int result = orderService.updateStatusToSend(parentsOrder);
        if (result == 0) {
            BaseRespVO errorResult = convertErrorResult("操作失败");
            return errorResult;
        }
        BaseRespVO baseRespVO = convertSuccessResult(result);
        return baseRespVO;
    }
}
